//
//  MYShopListClassSelectCell.m
//  MuYing
//
//  Created by tbb on 2019/7/25.
//  Copyright © 2019 TBB. All rights reserved.
//

#import "MYShopListClassSelectCell.h"
#import "MYShopListClassSelectCollViewCell.h"
#import "YQSepartionCollectionViewFlowLayout.h"
#import "MYShopSearchVC.h"

#import "MYNewsHotActionSearchVC.h"

#define collViewH (kScreenWidth-24)*(237/351.0)
@interface MYShopListClassSelectCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic ,strong) UICollectionView *hotClassColl;
@property (nonatomic, strong) NSMutableArray * titleArr;
@end

@implementation MYShopListClassSelectCell

- (void)setModel:(YQPShopSCatalogModel *)model
{
    _model = model;

    if (model.recommendCatalog2List.count) {
        [self.hotClassColl reloadData];
    }else{

    }
}

-(UICollectionView *)hotClassColl
{
    if (!_hotClassColl) {
        YQSepartionCollectionViewFlowLayout *layout=[[YQSepartionCollectionViewFlowLayout alloc]init];
//        layout.minimumLineSpacing= 1.0f;
//        layout.minimumInteritemSpacing= 1.0f;
        layout.scrollDirection=UICollectionViewScrollDirectionVertical;
        
        _hotClassColl = [[UICollectionView alloc] initWithFrame:CGRectMake(12, 0, kScreenWidth-24, collViewH) collectionViewLayout:layout];
        
        _hotClassColl.delegate=self;
        _hotClassColl.dataSource=self;
        _hotClassColl.backgroundColor=[UIColor whiteColor];
        [_hotClassColl setShowsHorizontalScrollIndicator:NO];
        
        _hotClassColl.layer.cornerRadius = 12;
        _hotClassColl.clipsToBounds = true;
        
        _hotClassColl.bounces = NO;
        
        [self.contentView addSubview:_hotClassColl];

        [_hotClassColl registerNib:[UINib nibWithNibName:@"MYShopListClassSelectCollViewCell" bundle:nil] forCellWithReuseIdentifier:@"MYShopListClassSelectCollViewCell"];
        
    }
    return _hotClassColl;
}

#pragma mark -- <UICollectionViewDelegate,UICollectionViewDataSource>
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.model.recommendCatalog2List.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YQPRecommendCatalog2Model *model = self.model.recommendCatalog2List[indexPath.item];
    MYShopListClassSelectCollViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MYShopListClassSelectCollViewCell" forIndexPath:indexPath];
    cell.titleLb.text = model.name;
    [cell.goodImageV sd_setImageWithURL:kURL(model.imageUrl) placeholderImage:IMAGE_NAMED(@"")];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat w = (kScreenWidth - 26) / 3.0;
    if (indexPath.row == 0 || indexPath.row == 1) {
        return CGSizeMake(floor((kScreenWidth - 25)) / 2.0,collViewH*(111.0/237));
    }
    
    return CGSizeMake(floor(w),collViewH*(125.0/237));
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 1.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 1.0;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    YQPRecommendCatalog2Model *model = self.model.recommendCatalog2List[indexPath.item];

    MYNewsHotActionSearchVC *searchVC = [[MYNewsHotActionSearchVC alloc] init];
    searchVC.categoryId = model.catalog2Id;
    [self.YQViewController.navigationController pushViewController:searchVC animated:true];

}
#pragma mark -- <UICollectionViewDelegate,UICollectionViewDataSource> end


-(void)layoutSubviews {
    [super layoutSubviews];
    self.contentView.backgroundColor = HexColor(0xF6F6F6);
    [self.hotClassColl reloadData];
}


@end
